package org.zw.android.framework.http;

import org.zw.android.framework.async.AsyncTaskHandler;

import android.content.Context;
import android.os.Message;

public abstract class HttpUIHandler extends AsyncTaskHandler {
	
	public static final int MSG_NORMAL_FILTER_FAILED		= MSG_STATUS_ERROR + 1 ;
	public static final int MSG_PARSER_FILTER_FAILED		= MSG_NORMAL_FILTER_FAILED + 1 ;
	
	public HttpUIHandler(Context context){
		super(context);
	}

	// Subclass override the method
	protected final void notifyUI(Message msg){
		
		if(msg.what == MSG_NORMAL_FILTER_FAILED){
			notifyNormalFilterFailed(msg);
		} if(msg.what == MSG_PARSER_FILTER_FAILED){
			notifyParserFilterFailed(msg);
		} else {
			notifyHttpUI(msg);
		}
	}
	
	// failed message
	protected abstract void notifyHttpUI(Message msg) ;
	
	// failed message
	protected abstract void notifyNormalFilterFailed(Message msg) ;
	
	// failed message
	protected abstract void notifyParserFilterFailed(Message msg) ;
	
	/**
	 * Normal Filter failed
	 */
	public void sendNormalFilterFailed(Object obj){
		obtainMessage(MSG_NORMAL_FILTER_FAILED,obj).sendToTarget();
	}
	
	/**
	 * Parser Filter failed
	 */
	public void sendParserFilterFailed(Object obj){
		obtainMessage(MSG_NORMAL_FILTER_FAILED,obj).sendToTarget();
	}
	
}
